package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    Student[] stu = new Student[5];

    public Student[] findStudent() {
        return stu;
    }

    public void addStudent(Student student) {
        int index= -1;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i]==null){
                index = i;
                break;
            }
        }
        if (index!=-1) {
            stu[index] = student;
        }
    }

    public void deleteStudent(String id) {
        for (int i = 0; i < stu.length; i++) {
            if (stu[i]!=null&&stu[i].getId().equals(id)){
                stu[i]=null;
                break;
            }
        }
    }

    public void updataStudent(String id, Student student) {
        int index = -1;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i] != null && stu[i].getId().equals(id)) {
                index = i;
                break;
            }
        }
        if (index!=-1) {
            stu[index] = student;
        }
    }
}
